package cn.DynamicDataSource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

@Slf4j
public class DynamicDataSource extends AbstractRoutingDataSource{

    @Override
    protected Object determineCurrentLookupKey() {
//        return DatabaseContextHolder.getCustomerType();
        String dataSourceName = DynamicDataSourceHolder.getDataSourceName();
        if (dataSourceName == null) {
//            dataSourceName = "PrimaryDatasource";
            dataSourceName = DataSourceName.PRIMARYDATASOURCE.getValue();
        }
        log.info("当前选择的数据源是:" + dataSourceName);
        return dataSourceName;
    }
}